<?php
/**
 * Created by PhpStorm.
 * User: wudiying
 * Date: 2020/2/19
 * Time: 下午9:54
 */

/**
 *
 * swoole之异步事件
 * 语法：
 * bool swoole_event_add(int $sock,mixed $read_callback,mixed $write_callback=null,int $flags=null);
 *
 */


// 模拟请求
$fp = stream_socket_client("tcp://www.qq.com:80",$error,$errstr,30);
fwrite($fp,"GET / HTTP/1.1\r\nHost:www.qq.com\r\n\r\n");


//添加异步事件
swoole_event_add($fp, function ($fp) {
    $resp = fread($fp, 8192); //8192 长度
    var_dump($resp);
    swoole_event_del($fp);
    fclose($fp);
});

echo "这个是异步的\n";